<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class HT_Model_administrator_models_application extends Zend_Db_Table {//ten class fai viet hoa

   protected $_db;
   protected $_appcat = 'application_cate';
    public function __construct() {
        $this->_name = "applications";
        $this->_db = Zend_Registry::get('dbMain');
        parent::init();
    }
    
    public function getAll($where){
        $sql = "select * from applications where ".$where;        
        $retval = $this->_db->fetchAll($sql);
        return $retval;
    }
    
    public function findById($id){
        $sql = "select * from applications where id = $id";
        $retval = $this->_db->fetchRow($sql);
        return $retval;
    }
    
    public function getappitem($id,$user_id) {
            $sql = "SELECT *, (SELECT COUNT(*) FROM application_like WHERE app_id = applications.id AND `status` = 1 AND application_like.user_id = '".$user_id."') AS liked FROM applications WHERE id = ?";            
            $retval = $this->_db->fetchAll($sql, array($id));
            return $retval[0];
        }
    
    /**
     * Get all applcation category
     * @return list 
     */
    public function getAllAppCat(){
        
       $select  = $this->_db->select()->from($this->_appcat, array('key' => 'id','value' => 'cate_name'));

       $result = $this->getAdapter()->fetchAll($select);

       return $result;
    }

}

?>
